//package com.group.app.example.config;
//
//import lombok.extern.log4j.Log4j2;
//import org.apache.http.HttpHost;
//import org.apache.http.auth.AuthScope;
//import org.apache.http.auth.UsernamePasswordCredentials;
//import org.apache.http.impl.client.BasicCredentialsProvider;
//import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
//import org.elasticsearch.client.RestClient;
//import org.elasticsearch.client.RestClientBuilder;
//import org.elasticsearch.client.RestHighLevelClient;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.beans.factory.config.AbstractFactoryBean;
//import org.springframework.context.annotation.Configuration;
//
////@Log4j2
////@Configuration
//public class ElasticsearchConfig extends AbstractFactoryBean {
//
//    @Value("${spring.elasticsearch.rest.host}")
//    private String host;
//
//    @Value("${spring.elasticsearch.rest.port}")
//    private int port;
//
//    @Value("${spring.elasticsearch.rest.username}")
//    private String user;
//
//    @Value("${spring.elasticsearch.rest.password}")
//    private String password;
//
//    private RestHighLevelClient restHighLevelClient;
//
//
//    @Override
//    public void destroy() throws Exception {
//        if(restHighLevelClient != null){
//            restHighLevelClient.close();
//        }
//    }
//
//    @Override
//    public boolean isSingleton(){ return  false;}
//
//    @Override
//    public Class<?> getObjectType() {
//        return RestHighLevelClient.class;
//    }
//
//    @Override
//    protected Object createInstance() throws Exception {
//        BasicCredentialsProvider credentialsProvider =new BasicCredentialsProvider();
//        credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials(user,password));
//        try {
//            restHighLevelClient=new RestHighLevelClient(
//                    RestClient.builder(new HttpHost(host,port,"http"))
//                    .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
//                        @Override
//                        public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
//                            return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
//                        }
//                    })
//            );
//        }catch (Exception e){
//            logger.error(e);
//        }
//        return restHighLevelClient;
//    }
//}
